﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using db.view.New;
using web.Controllers;

namespace web.Areas.admin.Controllers
{
    [RouteArea("admin")]
    public class MatchController : baseController
    {
        public ActionResult Select(MatchInfo model)
        {
            model.Search();
            if (rui.requestHelper.isAjax())
                return PartialView("_showData", model);
            return View(model);
        }


        //展示详情
        public ActionResult Detail(string rowID)
        {
            MatchInfo model = MatchInfo.getEntryByRowID(rowID, dc);
            return View(model);
        }

        //展示新增
        [HttpGet]
        public ActionResult Insert()
        {
            MatchInfo model = new MatchInfo();
            return View(model);
        }

        //保存新增
        [HttpPost]
        public JsonResult Insert(MatchInfo model)
        {
            rui.jsonResult result = new rui.jsonResult();
            try
            {
                if (ModelState.IsValid)
                {
                    string orgCode = db.bll.loginAdminHelper.getOrgCode();
                    string rowID = MatchInfo.createRelatedUser(model, dc);
                    result.data = rui.jsonResult.getAJAXResult("新增成功", true,
                        null);
                }
                else
                {
                    result.data = rui.jsonResult.getAJAXResult("输入不合法", false);
                }
            }
            catch (Exception ex)
            {
                rui.logHelper.log(ex);
                result.data = rui.jsonResult.getAJAXResult(rui.excptHelper.getExMsg(ex), false);
            }
            return Json(result.data);
        }

        // //展示更新
        // [HttpGet]
        // public ActionResult Update(string rowID)
        // {
        //     MatchInfo model = MatchInfo.getEntryByRowID(rowID, dc);
        //     return View(model);
        // }
        //
        // //保存更新
        // [HttpPost]
        // public JsonResult Update(MatchInfo model)
        // {
        //     rui.jsonResult result = new rui.jsonResult();
        //     try
        //     {
        //         if (ModelState.IsValid)
        //         {
        //             MatchInfo.update(model, dc);
        //             result.data = rui.jsonResult.getAJAXResult("更新成功", true);
        //         }
        //         else
        //         {
        //             result.data = rui.jsonResult.getAJAXResult("输入不合法", false);
        //         }
        //     }
        //     catch (Exception ex)
        //     {
        //         rui.logHelper.log(ex);
        //         result.data = rui.jsonResult.getAJAXResult(rui.excptHelper.getExMsg(ex), false);
        //     }
        //     return Json(result.data);
        // }
        //
        // //删除
        // [HttpPost]
        // public JsonResult Delete(string rowID)
        // {
        //     rui.jsonResult result = new rui.jsonResult();
        //     try
        //     {
        //         string keyCode = MatchInfo.getCodeByRowID(rowID, dc);
        //         MatchInfo.delete(keyCode, dc);
        //         result.data = rui.jsonResult.getAJAXResult("删除成功", true);
        //     }
        //     catch (Exception ex)
        //     {
        //         rui.logHelper.log(ex);
        //         result.data = rui.jsonResult.getAJAXResult(rui.excptHelper.getExMsg(ex), false);
        //     }
        //     return Json(result.data);
        // }

    }
}